package team526.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import team526.dao.VideoDao;
import team526.entity.Video;
import team526.service.VideoService;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

/**
 * #Date 2021/9/27 - 15:53
 *
 * @author 王铭 20181620310021
 */
@RestController
@CrossOrigin
public class DevController {

    @Autowired
    VideoService videoService;

    @Autowired
    VideoDao videoDao;

    @PostMapping("upload_dev")
    Video saveTogether(@RequestParam("uuid") Integer uuid,
                       @RequestParam("desc") String desc,
                       @RequestParam("title") String title,
                       @RequestParam("main_tag_id") Integer main_tag_id,
                       @RequestPart("file") MultipartFile video_file,
                       @RequestPart("pic") MultipartFile video_pic) throws IOException {

        return new Video();
    }

    @PostMapping("upload_test/{uuid}/{main_tag_id}")
    public String saveTest(@RequestParam("duration") Integer duration,
                           @PathVariable Integer uuid,
                           @PathVariable Integer main_tag_id,
                           @RequestParam("title") String title,
                           @RequestParam("tid") Integer tid,
                           @RequestParam("desc") String desc,
                           @RequestPart MultipartFile file,
                           @RequestPart MultipartFile pic) throws IOException {
        System.out.println(title);
        System.out.println(duration);
        System.out.println(main_tag_id);
        System.out.println(desc);

        HashMap<Integer, Integer> tagMap = new HashMap<>();
        tagMap.put(208, 1);
        tagMap.put(231, 2);
        tagMap.put(21, 3);
        tagMap.put(238, 4);
        tagMap.put(17, 5);
        tagMap.put(71, 6);
        tagMap.put(229, 7);

        Video video = videoService.saveVideoWithFullPart(uuid, title, tagMap.get(tid), desc, duration, null, null, file, pic);

        Random r = new Random();

        videoDao.setPlayNum(r.nextInt(1000), video.getVideoid());

        return video.getStorage();
    }
}
